package program;

import java.util.*;

public class TrainManager {

	private ArrayList<Train> listOfTrains = new ArrayList<Train>();
	
	public TrainManager() {
	}

	public Train createNewTrain(){
		Train train = new Train();
		listOfTrains.add(train);
		return train;
	}
	
	public boolean removeTrain(Integer id){
		if(id == null) throw new IllegalArgumentException("Cannot have null parameter");
		
		for(int i=0; i< listOfTrains.size();i++)
		{
			if(listOfTrains.get(i).getID()==id) listOfTrains.remove(i);
			return true;
		}
		return false;
	}
	
	public ArrayList<Train> getListOfTrains(){
		return listOfTrains;
	}
	
	public Train getTrainByID(int id){
		for(int i=0;i<listOfTrains.size();i++){
			if(listOfTrains.get(i).getID()==id)
				return listOfTrains.get(i);
		}
		throw new IllegalArgumentException("Train ID not found");
	}
}
